<?php

use think\migration\db\Column;
use think\migration\Migrator;

class AddWechatAccountSystem extends Migrator
{
    protected $tableWechatAccount = 'wechat_account';

    public function up()
    {
        $this->createWechatAccount();
    }

    public function down()
    {
        $this->dropWechatAccount();
    }

    protected function createWechatAccount()
    {
        if (!$this->hasTable($this->tableWechatAccount)) {
            $table = $this->table($this->tableWechatAccount, ['engine' => 'InnoDB', 'comment' => '使用的公众号信息']);
            $table->addColumn(Column::string('title', 40)->setComment('公众号名称'))
                ->addColumn(Column::string('gh_id', 20)->setComment('公众号原始ID')->setUnique())
                ->addColumn(Column::string('app_id', 40)->setComment('公众号appid')->setUnique())
                ->addColumn(Column::string('secret', 100)->setComment('公众号密钥'))
                ->addColumn(Column::string('token', 32)->setComment('公众号验证token'))
                ->addColumn(Column::char('encrypt_key', 43)->setComment('公众号消息加密私钥'))
                ->addColumn(Column::boolean('type')->setComment('公众号类型，1订阅号2服务号3认证订阅号4认证服务号5企业号'))
                ->addColumn(Column::boolean('status')->setComment('公众号状态，0不可用1可用'))
                ->addColumn(Column::integer('create_at')->setComment('记录添加时间'))
                ->addColumn(Column::integer('update_at')->setComment('记录修改时间'))
                ->create();
        }
    }

    protected function dropWechatAccount()
    {
        if ($this->hasTable($this->tableWechatAccount)) {
            $this->dropTable($this->tableWechatAccount);
        }
    }
}
